/* $Id: JLogoDesktopPane.java 43 2009-12-25 12:40:31Z aaron.day $ */
package org.crazydays.gameplan.swing;


import java.awt.Graphics;
import javax.swing.JDesktopPane;

import org.crazydays.gameplan.Logo;

/**
 * JLogoDesktopPane
 */
public class JLogoDesktopPane
    extends JDesktopPane
{
    /** serial version uid */
    public final static long serialVersionUID =
        "$Id: JLogoDesktopPane.java 43 2009-12-25 12:40:31Z aaron.day $"
            .hashCode();

    /** logo */
    protected Logo logo;

    /**
     * Paint component.
     * 
     * @param graphics Graphics
     * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
     */
    protected void paintComponent(Graphics graphics)
    {
        super.paintComponent(graphics);
        paintLogo(graphics);
    }

    /**
     * Paint logo.
     * 
     * @param graphics Graphics
     */
    protected void paintLogo(Graphics graphics)
    {
        int dimension = Math.min(getWidth(), getHeight());

        // if logo is null or not equal to current size
        if (logo == null || dimension != logo.getImage().getWidth()) {
            logo = new Logo(dimension, dimension);
        }

        int xoff = (getWidth() - dimension) / 2;
        int yoff = (getHeight() - dimension) / 2;

        graphics.drawImage(logo.getImage(), xoff, yoff, logo.getImage()
            .getWidth(), logo.getImage().getHeight(), this);
    }
}
